package com.zx.bus.controller;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zx.bus.domain.Rent;
import com.zx.bus.service.CheckService;
import com.zx.bus.service.RentService;
import com.zx.bus.vo.CheckVo;
import com.zx.sys.constast.SysConstast;
import com.zx.sys.utils.DataGridView;
import com.zx.sys.utils.ResultObj;

@RestController
@RequestMapping("check")
public class CheckController {

	@Autowired
	private CheckService checkService;
	
	@Autowired
	private RentService rentService;
	
	@RequestMapping("loadAllCheck")
	public DataGridView loadAllCheck(CheckVo checkVo){
		return checkService.queryAllCheck(checkVo);
	}
	
	@RequestMapping("checkRentExist")
	public Rent checkRentExist(String rentid){
		Rent rent = rentService.queryRentByRentId(rentid);
		return rent;
	}
	
	@RequestMapping("initCheckFormData")
	public Map<String, Object> initCheckFormData(String rentid){
		return checkService.initCheckFormData(rentid);
	}
	
	@RequestMapping("saveCheck")
	public ResultObj saveCheck(CheckVo checkVo){
		try {
			checkVo.setCreatetime(new Date());
			checkService.addCheck(checkVo);
			return new ResultObj(SysConstast.CODE_SUCCESS, SysConstast.ADD_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultObj(SysConstast.CODE_ERROR, SysConstast.ADD_ERROR);
		}
	}
	
	@RequestMapping("updateCheck")
	public ResultObj updateCheck(CheckVo checkVo){
		try {
			checkService.updateCheck(checkVo);
			return new ResultObj(SysConstast.CODE_SUCCESS, SysConstast.UPDATE_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultObj(SysConstast.CODE_ERROR, SysConstast.UPDATE_ERROR);
		}
	}
}
